package com.lebang.service;


import com.lebang.domain.CustomerMemberDiscontent;
import com.lebang.example.CustomerMemberContentmentExample;
import com.lebang.example.CustomerMemberDiscontentExample;
import com.lebang.mapper.CustomerMemberContentmentMapper;
import com.lebang.mapper.CustomerMemberDiscontentMapper;
import com.lebang.model.FeedbackModel;
import com.lebangweb.common.TextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class CustomerMemberDiscontentService extends BaseService<CustomerMemberDiscontent,Long, CustomerMemberDiscontentExample> {

    @Autowired
    private CustomerMemberDiscontentMapper customerMemberDiscontentMapper;
    @Autowired
    private CustomerMemberContentmentMapper customerMemberContentmentMapper;

    public Long getCount(Integer page,Integer limit){
        CustomerMemberDiscontentExample example = new CustomerMemberDiscontentExample();
        example.setOffset((page - 1) * limit.longValue());
        example.setLimit(limit);
        return customerMemberDiscontentMapper.countByExample(example);
    }

    public FeedbackModel selectByStatistics(LocalDateTime star, LocalDateTime end, String appStore) {
        CustomerMemberContentmentExample customerMemberContentmentExample=new CustomerMemberContentmentExample();
        CustomerMemberContentmentExample.Criteria criteria = customerMemberContentmentExample.createCriteria();

        CustomerMemberDiscontentExample appDiscontentExample=new CustomerMemberDiscontentExample();
        CustomerMemberDiscontentExample.Criteria customerCriteria = appDiscontentExample.createCriteria();

        if (!TextUtil.isEmpty(star, end)) {
            customerCriteria.andCreateTimeBetween(star, end);
            criteria.andCreateTimeBetween(star,end);
        }

        if (!TextUtil.isEmpty(appStore)){
            customerCriteria.andAppStoreEqualTo(appStore);
            criteria.andAppStoreEqualTo(appStore);
        }
        //查询不满意总数
        long appDiscontentNum = customerMemberDiscontentMapper.countByExample(appDiscontentExample);

        //查询满意总数
        long contentmentNum = customerMemberContentmentMapper.countByExample(customerMemberContentmentExample);

        //满意度总数
        Long sum=contentmentNum+appDiscontentNum;
        List<CustomerMemberDiscontent> customerMemberDiscontents = customerMemberDiscontentMapper.selectCount(star, end, appStore);

        FeedbackModel feedbackModel=new FeedbackModel();
        feedbackModel.setAllCount(sum);
        feedbackModel.setDiscontentCount(appDiscontentNum);
        feedbackModel.setContentmentCount(contentmentNum);
        feedbackModel.setListCount(customerMemberDiscontents);
        return feedbackModel;
    }
}
